package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcZdjzdl;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcZdjzdlMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcZdjzdlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车最大静制动力Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcZdjzdlServiceImpl implements IDataWgjlcZdjzdlService
{
    @Autowired
    private DataWgjlcZdjzdlMapper dataWgjlcZdjzdlMapper;

    /**
     * 查询无轨胶轮车最大静制动力
     * 
     * @param zdjzdlId 无轨胶轮车最大静制动力主键
     * @return 无轨胶轮车最大静制动力
     */
    @Override
    public DataWgjlcZdjzdl selectDataWgjlcZdjzdlByZdjzdlId(Long zdjzdlId)
    {
        return dataWgjlcZdjzdlMapper.selectDataWgjlcZdjzdlByZdjzdlId(zdjzdlId);
    }

    /**
     * 查询无轨胶轮车最大静制动力列表
     * 
     * @param dataWgjlcZdjzdl 无轨胶轮车最大静制动力
     * @return 无轨胶轮车最大静制动力
     */
    @Override
    public List<DataWgjlcZdjzdl> selectDataWgjlcZdjzdlList(DataWgjlcZdjzdl dataWgjlcZdjzdl)
    {
        return dataWgjlcZdjzdlMapper.selectDataWgjlcZdjzdlList(dataWgjlcZdjzdl);
    }

    /**
     * 新增无轨胶轮车最大静制动力
     * 
     * @param dataWgjlcZdjzdl 无轨胶轮车最大静制动力
     * @return 结果
     */
    @Override
    public int insertDataWgjlcZdjzdl(DataWgjlcZdjzdl dataWgjlcZdjzdl)
    {
        dataWgjlcZdjzdl.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcZdjzdlMapper.insertDataWgjlcZdjzdl(dataWgjlcZdjzdl);
    }

    /**
     * 修改无轨胶轮车最大静制动力
     * 
     * @param dataWgjlcZdjzdl 无轨胶轮车最大静制动力
     * @return 结果
     */
    @Override
    public int updateDataWgjlcZdjzdl(DataWgjlcZdjzdl dataWgjlcZdjzdl)
    {
        dataWgjlcZdjzdl.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcZdjzdl.getTestOneDataList().isEmpty()) {
            dataWgjlcZdjzdl.setDataList(JSON.toJSONString(dataWgjlcZdjzdl.getTestOneDataList()));
        }
        return dataWgjlcZdjzdlMapper.updateDataWgjlcZdjzdl(dataWgjlcZdjzdl);
    }

    /**
     * 查询无轨胶轮车-最大静制动力
     *
     * @param dataTaskId
     * @return 无轨胶轮车-最大静制动力
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcZdjzdl>> selectDataWgjlcZdjzdlByDataTaskId(Long dataTaskId) {
        List<DataWgjlcZdjzdl> dataWgjlcZdjzdlEntities = dataWgjlcZdjzdlMapper.selectDataWgjlcZdjzdlByDataTaskId(dataTaskId);
        if (dataWgjlcZdjzdlEntities.size() != 0) {
            dataWgjlcZdjzdlEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcZdjzdlEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcZdjzdlByDataTaskId(Long dataTaskId) {
        return dataWgjlcZdjzdlMapper.updateDataWgjlcZdjzdlByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-最大静制动力
     *
     * @param dataWgjlcZdjzdl 无轨胶轮车-最大静制动力
     * @return 结果
     */
    @Override
    public int batchDataWgjlcZdjzdl(List<DataWgjlcZdjzdl> dataWgjlcZdjzdl) {
        return dataWgjlcZdjzdlMapper.batchDataWgjlcZdjzdl(dataWgjlcZdjzdl);
    }

    /**
     * 批量删除无轨胶轮车最大静制动力
     * 
     * @param zdjzdlIds 需要删除的无轨胶轮车最大静制动力主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcZdjzdlByZdjzdlIds(Long[] zdjzdlIds)
    {
        return dataWgjlcZdjzdlMapper.deleteDataWgjlcZdjzdlByZdjzdlIds(zdjzdlIds);
    }

    /**
     * 删除无轨胶轮车最大静制动力信息
     * 
     * @param zdjzdlId 无轨胶轮车最大静制动力主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcZdjzdlByZdjzdlId(Long zdjzdlId)
    {
        return dataWgjlcZdjzdlMapper.deleteDataWgjlcZdjzdlByZdjzdlId(zdjzdlId);
    }
}
